package com.yy.controller;

import com.yy.api.AIServiceClient;
import com.yy.api.UserServiceClient;
import com.yy.common.BaseResponse;
import com.yy.model.vo.LoginUserVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Stack;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
@Slf4j
public class TestController {
    StringBuilder stringBuilder = new StringBuilder();
    Stack<String> stack = new Stack<>();
    private final   UserServiceClient userServiceClient;

    @GetMapping("/hello")
    public String hello(HttpServletRequest request) {
        log.info("hello");
        String sessionId = request.getHeader("SessionId");
        log.info("sessionId:{}", sessionId);
        //测试
        BaseResponse<LoginUserVO> loginUser = userServiceClient.getLoginUser();
        if (loginUser != null) {
            log.info("loginUser:{}", loginUser);
        }
        return "hello world";
    }
}


/**
 * @author yuyao
 * 失败后的降级处理
 */
class A implements FallbackFactory<AIServiceClient> {
    @Override
    public AIServiceClient create(Throwable cause) {
        return new AIServiceClient() {
            @Override
            public String getAnswer(String question) {
                return null;
            }
        };
    }
}
